/**
 * \file
 *
 * \brief User board definition template
 *
 */

 /* This file is intended to contain definitions and configuration details for
 * features and devices that are available on the board, e.g., frequency and
 * startup time for an external crystal, external memory devices, LED and USART
 * pins.
 */

#ifndef USER_BOARD_H
#define USER_BOARD_H

#include <conf_board.h>


// ############################# PORT DEFINITIONS #############################

// ADC Current sensor
#define CURRENT_SENSOR_ADC_MODULE         ADCB
#define CURRENT_SENSOR_ADC_INPUT          ADCCH_POS_PIN6
#define CURRENT_SENSOR_SIGNAL_PIN         IOPORT_CREATE_PIN(PORTB, 6)

// Vienna RobotChallenge IR module
#define REMOTE_START IOPORT_CREATE_PIN(PORTK, 0)        // SW_1
#define REMOTE_KILL IOPORT_CREATE_PIN(PORTK, 1)         // SW_2

// Buttons
#define MY_BUTTON1 IOPORT_CREATE_PIN(PORTH, 3)		// SW_1
#define MY_BUTTON2 IOPORT_CREATE_PIN(PORTH, 2)		// SW_2
#define MY_BUTTON3 IOPORT_CREATE_PIN(PORTH, 4)		// SW_3
#define MY_BUTTON4 IOPORT_CREATE_PIN(PORTH, 5)		// SW_4
#define MY_BUTTON5 IOPORT_CREATE_PIN(PORTH, 6)		// SW_5

// Rotary switch
#define ROTARY_PORT  IOPORT_PORTA
#define ROTARY1 IOPORT_CREATE_PIN(PORTA, 3)			// ROTARY_1
#define ROTARY2 IOPORT_CREATE_PIN(PORTA, 5)			// ROTARY_2
#define ROTARY4 IOPORT_CREATE_PIN(PORTA, 4)			// ROTARY_3
#define ROTARY8 IOPORT_CREATE_PIN(PORTA, 2)			// ROTARY_4

// Encoders
#define ENCODER_L IOPORT_CREATE_PIN(PORTA, 6)       // ENCODER_2 (ENCODER_R)
#define ENCODER_R IOPORT_CREATE_PIN(PORTA, 7)       // ENCODER_1 (ENCODER_L)

// Motors
#define MOTOR_L1 IOPORT_CREATE_PIN(PORTD, 4)		// MOTOR_L1 (DRVR_PWMA)		1 Top
#define MOTOR_L2 IOPORT_CREATE_PIN(PORTD, 1)		// MOTOR_L2 (DRVR_PWMB)		1 Bottom
#define MOTOR_L3 IOPORT_CREATE_PIN(PORTD, 2)		// MOTOR_L3 (DRVR_PWMC)		2 Bottom
#define MOTOR_L4 IOPORT_CREATE_PIN(PORTD, 3)		// MOTOR_L4 (DRVR_PWMD)		2 Top
#define MOTOR_R1 IOPORT_CREATE_PIN(PORTE, 0)		// MOTOR_R1 (DRVL_PWMA)
#define MOTOR_R2 IOPORT_CREATE_PIN(PORTE, 1)		// MOTOR_R2 (DRVL_PWMB)
#define MOTOR_R3 IOPORT_CREATE_PIN(PORTE, 2)		// MOTOR_R3 (DRVL_PWMC)
#define MOTOR_R4 IOPORT_CREATE_PIN(PORTE, 3)		// MOTOR_R4 (DRVL_PWMD)

// initialize servo
//#define SERVO_R IOPORT_CREATE_PIN(PORTD, 4)         // SERVO_1 (FLAG_R)  // vadinsh uz MOTOR_L1
#define SERVO_L IOPORT_CREATE_PIN(PORTD, 5)         // SERVO_2 (FLAG_L

// Line sensors
#define LINE_SENSOR_PORT  IOPORT_PORTF
#define LINE_BR IOPORT_CREATE_PIN(PORTF, 0)			// LINE_1 (LINE_BR)
#define LINE_FR IOPORT_CREATE_PIN(PORTF, 1)			// LINE_2 (LINE_FL)
#define LINE_FL IOPORT_CREATE_PIN(PORTF, 2)			// LINE_3 (LINE_FR)
#define LINE_BL IOPORT_CREATE_PIN(PORTF, 3)			// LINE_4 (LINE_BL)

// IR start/stop(kill switch)
#define KILL_SW IOPORT_CREATE_PIN(PORTH, 0)         // IR KILL SWITCH
#define START_SW IOPORT_CREATE_PIN(PORTH, 1)        // START IR SWITCH

// Distance sensor power
#define POWER_PORT  IOPORT_PORTB
#define SENSOR_PWR_L IOPORT_CREATE_PIN(PORTB, 5)	// SENSOR_1PWR (OBJ_L_PWR)
#define SENSOR_PWR_FL IOPORT_CREATE_PIN(PORTB, 4)	// SENSOR_2PWR (OBJ_FL_PWR)
#define SENSOR_PWR_F IOPORT_CREATE_PIN(PORTB, 3)	// SENSOR_3PWR (OBJ_F_PWR)
#define SENSOR_PWR_FR IOPORT_CREATE_PIN(PORTB, 2)	// SENSOR_4PWR (OBJ_FR_PWR)
#define SENSOR_PWR_R IOPORT_CREATE_PIN(PORTB, 1)	// SENSOR_5PWR (OBJ_R_PWR)

// Distance sensors
#define PANASONIC_PORT  IOPORT_PORTC
#define PANASONIC_R90 IOPORT_CREATE_PIN(PORTC, 0)	// SENSOR1 (OBJ_R_2)
#define PANASONIC_R45 IOPORT_CREATE_PIN(PORTC, 1)	// SENSOR2 (OBJ_R_1)
#define PANASONIC_FR2 IOPORT_CREATE_PIN(PORTC, 2)	// SENSOR3 (OBJ_FR_2)
#define PANASONIC_FR1 IOPORT_CREATE_PIN(PORTC, 3)	// SENSOR4 (OBJ_FR_1)
#define PANASONIC_FL1 IOPORT_CREATE_PIN(PORTC, 4)	// SENSOR5 (OBJ_FL_1)
#define PANASONIC_FL2 IOPORT_CREATE_PIN(PORTC, 5)	// SENSOR6 (OBJ_FL_2)
#define PANASONIC_L45 IOPORT_CREATE_PIN(PORTC, 6)	// SENSOR7 (OBJ_L_1)
#define PANASONIC_L90 IOPORT_CREATE_PIN(PORTC, 7)	// SENSOR8 (OBJ_L_2)

#define PEPPERL_FUCHS IOPORT_CREATE_PIN(PORTQ, 0)   // SENSOR9 (OBJ_F_2)  GT vadish

// Blue-tooth module for debugging and data logging
#define USART_SERIAL                     &USARTD1
#define USART_SERIAL_BAUDRATE            19200
#define USART_SERIAL_CHAR_LENGTH         USART_CHSIZE_8BIT_gc
#define USART_SERIAL_PARITY              USART_PMODE_DISABLED_gc
#define USART_SERIAL_STOP_BIT            true


// LCD controller (NHD-C12832A1Z-FSW-FBW-3V3)
#define NHD_C12832A1Z_SPI               &SPIF
#define NHD_C12832A1Z_SPI_SCK	        IOPORT_CREATE_PIN(PORTF, 7)     // SCK	<=
#define NHD_C12832A1Z_SPI_MOSI          IOPORT_CREATE_PIN(PORTF, 5)     // MOSI	<=
#define NHD_C12832A1Z_CSN               IOPORT_CREATE_PIN(PORTJ, 3)     // LCD_CS
// If this signal is set high display data is sent otherwise commands
#define NHD_C12832A1Z_REGISTER_SELECT   IOPORT_CREATE_PIN(PORTJ, 5)     // LCD_CMD
#define NHD_C12832A1Z_RESETN            IOPORT_CREATE_PIN(PORTJ, 4)     // LCD_RST (pull-up)
// The back-light is active high
#define NHD_C12832A1Z_BACKLIGHT         IOPORT_CREATE_PIN(PORTJ, 2)     // LCD_LED
// The SPIF SS pin
#define LED_LATCH                       IOPORT_CREATE_PIN(PORTF, 4)     // SPIF_SS (pull-up)


#endif // USER_BOARD_H
